<cfparam default="" name="PageType" />

<cfoutput>

    <!---BillingReport is set in showreport--->

    <cfscript>
        BillingStruct = {
            Chore = 8568,
            Meals = 8575,
            Transportation = 8564,
            TTCM = 5985
        };
    </cfscript>

    <cfif PageType EQ "XLS">
    	<!--- Set this HTTP Document as an Excel Spreadsheet --->
        <cfheader name="Content-Type:" value="application/vnd.ms-excel">
        <cfheader name="Content-Disposition:" value="attachment; filename=BillingReport_From_#url.DateFrom#_to_#url.DateTo#.xls">

        <!--- Output ONLY items enclosed in CF tags --->
		<cfsetting enablecfoutputonly="true">
            <table id="report" style="border:1px solid ##000">
                <thead>
                    <tr>
                        <th style="border:1px solid ##000">Case ID</th>
                        <th style="border:1px solid ##000">Last Name</th>
                        <th style="border:1px solid ##000">First Name</th>
                        <th style="border:1px solid ##000">Date of Birth</th>
                        <th style="border:1px solid ##000">Service</th>
                        <th style="border:1px solid ##000">Billing Code</th>
                        <th style="border:1px solid ##000">Date of Service</th>
                        <th style="border:1px solid ##000">Provider Name</th>
                        <th style="border:1px solid ##000">Provider ID</th>
                        <th style="border:1px solid ##000">Units</th>
                        <th style="border:1px solid ##000">PriorAuth</th>
                    </tr>
                </thead>
                <tbody>
                    <cfloop query="BillingReport" >
                    	<cfset getCaseID = CreateObject("component", "elders.cfc.reports").funcQryGetCaseID(
						BillingReport.LastName,
						BillingReport.FirstName,
						DateFormat(BillingReport.DOB, "mm/dd/yyyy")
						) />
                        <tr>
                            <td style="border:1px solid ##000" align="center">#getCaseID.CaseID#</td>
                            <td style="border:1px solid ##000">#BillingReport.LastName#</td>
                            <td style="border:1px solid ##000">#BillingReport.FirstName#</td>
                            <td style="border:1px solid ##000" align="center">#DateFormat(BillingReport.DOB, "mm/dd/yyyy")#</td>
                            <td style="border:1px solid ##000">#BillingReport.ServiceType#</td>
                            <td style="border:1px solid ##000" align="center">#BillingStruct[BillingReport.ServiceType]#</td>
                            <td style="border:1px solid ##000" align="center">#DateFormat(BillingReport.DateOfService, "mm/dd/yyyy")#</td>
                            <cfset findProvider = CreateObject("component", "elders.cfc.utilities").funcFindProvider(BillingReport.ProviderID) />
                            <td style="border:1px solid ##000">#findProvider.ProviderName#</td>
                            <td style="border:1px solid ##000">#findProvider.ProviderID#</td>
                            <td style="border:1px solid ##000" align="center">#BillingReport.TotalUnits#</td>
                            <td style="border:1px solid ##000" align="center">#getCaseID.PriorAuth#</td>
                        </tr>
                    </cfloop>
                </tbody>
            </table>

        </cfsetting>

    <cfelseif PageType EQ "PDF">

       <cfdocument format="pdf">

       <cfset pageCount = 0 />

       <cfdocumentitem type= "footer">
			#cfdocument.currentpagenumber# of #cfdocument.totalpagecount#
       </cfdocumentitem>


    	<h2>Billing Report - From #url.DateFrom# to #url.DateTo#</h2>

        <table cellpadding="1" cellspacing="0" style="page-break-after:always;border:1px solid ##000;font-size:10px" fontembed="yes" >

                <thead >
                    <tr>
                        <th align="left" style="border:1px solid ##000">Case ID</th>
                        <th align="left" style="border:1px solid ##000">Last Name</th>
                        <th align="left" style="border:1px solid ##000">First Name</th>
                        <th align="left" style="border:1px solid ##000">Date of Birth</th>
                        <th align="left" style="border:1px solid ##000">Service</th>
                        <th align="left" style="border:1px solid ##000">Billing Code</th>
                        <th align="left" style="border:1px solid ##000">Date of Service</th>
                        <th align="left" style="border:1px solid ##000">Provider Name</th>
                        <th align="left" style="border:1px solid ##000">Provider ID</th>
                        <th align="left" style="border:1px solid ##000">Units</th>
                        <th align="left" style="border:1px solid ##000">PriorAuth</th>
                    </tr>
                </thead>

                <cfloop query="BillingReport" >
                	<cfset getCaseID = CreateObject("component", "elders.cfc.reports").funcQryGetCaseID(
						BillingReport.LastName,
						BillingReport.FirstName,
						DateFormat(BillingReport.DOB, "mm/dd/yyyy")
					) />
                    <tbody>
                        <tr>
                            <td style="border:1px solid ##000" align="center">#getCaseID.CaseID#</td>
                            <td style="border:1px solid ##000"><a href="intake.cfm?ElderID=#BillingReport.ElderListID#">#BillingReport.LastName#</a></td>
                            <td style="border:1px solid ##000"><a href="intake.cfm?ElderID=#BillingReport.ElderListID#">#BillingReport.FirstName#</a></td>
                            <td style="border:1px solid ##000"  align="center">#DateFormat(BillingReport.DOB, "mm/dd/yyyy")#</td>
                            <td style="border:1px solid ##000">#BillingReport.ServiceType#</td>
                            <td style="border:1px solid ##000"  align="center">#BillingStruct[BillingReport.ServiceType]#</td>
                            <cfif BillingReport.ServiceType NEQ "Meals">
                                <td style="border:1px solid ##000">
                                    <a href="dailyprogressnote.cfm?ElderID=#BillingReport.ElderListID#&DailyProgressNoteID=#BillingReport.ServiceID#">
                                    	#DateFormat(BillingReport.DateOfService, "mm/dd/yyyy")#
                                    </a>
                                </td>
                            <cfelse>
                            	<td style="border:1px solid ##000">#DateFormat(BillingReport.DateOfService, "mm/dd/yyyy")#</td>
                         	</cfif>
                         	<cfset findProvider = CreateObject("component", "EPMD.cfc.utilities").funcFindProvider(BillingReport.ProviderID) />
                            <td style="border:1px solid ##000">#findProvider.ProviderName#</td>
                            <td style="border:1px solid ##000">#findProvider.ProviderID#</td>
                            <td style="border:1px solid ##000" align="center">#BillingReport.TotalUnits#</td>
                            <td style="border:1px solid ##000" align="center">#getCaseID.PriorAuth#</td>
                        </tr>
                    </tbody>
                </cfloop>

        </table>

        </cfdocument>

    <cfelse>

		<!---HTML header, css links, js links, and page title--->
        #BASE.htmlHeader("",
        "", "Elder's Program - Reports")#
        <!---HTML header, css links, js links, and page title--->

        <h2>Billing Report - From #url.DateFrom# to #url.DateTo#</h2>

        <table>
            <thead>
                <tr>
                    <th>Case ID</th>
                    <th>Last Name</th>
                    <th>First Name</th>
                    <th>Date of Birth</th>
                    <th>Service</th>
                    <th>Billing Code</th>
                    <th>Date of Service</th>
                    <th>Provider Name</th>
                    <th>Provider ID</th>
                    <th>Units</th>
                    <th>PriorAuth</th>
                </tr>
            </thead>
            <tbody>
                <cfloop query="BillingReport" >
					<cfset getCaseID = CreateObject("component", "elders.cfc.reports").funcQryGetCaseID(
						BillingReport.LastName,
						BillingReport.FirstName,
						DateFormat(BillingReport.DOB, "mm/dd/yyyy")
					) />
                    <tr>
                        <td>#getCaseID.CaseID#</td>
                        <td><a href="intake.cfm?ElderID=#BillingReport.ElderListID#">#BillingReport.LastName#</a></td>
                        <td><a href="intake.cfm?ElderID=#BillingReport.ElderListID#">#BillingReport.FirstName#</a></td>
                        <td>#DateFormat(BillingReport.DOB, "mm/dd/yyyy")#</td>
                        <td>#BillingReport.ServiceType#</td>
                        <td>#BillingStruct[BillingReport.ServiceType]#</td>
                        <cfif BillingReport.ServiceType NEQ "Meals">
                            <td>
                                <a href="dailyprogressnote.cfm?ElderID=#BillingReport.ElderListID#&DailyProgressNoteID=#BillingReport.ServiceID#">
                                	#DateFormat(BillingReport.DateOfService, "mm/dd/yyyy")#
                                </a>
                            </td>
                         <cfelse>
                         	<td>#DateFormat(BillingReport.DateOfService, "mm/dd/yyyy")#</td>
                         </cfif>
                        <cfset findProvider = CreateObject("component", "elders.cfc.utilities").funcFindProvider(BillingReport.ProviderID) />
                        <td>#findProvider.ProviderName#</td>
                        <td>#findProvider.ProviderID#</td>
                        <td>#BillingReport.TotalUnits#</td>
                        <td>#getCaseID.PriorAuth#</td>
                    </tr>
                </cfloop>
            </tbody>
        </table>

        <!---HTML footer, closes html and body tags.  Any footer info goes here--->
        #BASE.htmlFooter()#
        <!---HTML footer, closes html and body tags.  Any footer info goes here--->

    </cfif>
</cfoutput>